﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CreditCardCompareRequestDB
/// </summary>
/// 
namespace CE.CreditCard
{
    public class CreditCardCompareRequestDB
    {
        public CreditCardCompareRequestDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CreditCardCompareRequest cccomparequest)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCCCApplicantRequestInsertSingleItem";
            SortedList _sPara = new SortedList();

            _sPara.Add("@CCCAppReqId", cccomparequest.CCCAppReqId);
            _sPara.Add("@RefCEUserId", cccomparequest.RefCEUserId);
			_sPara.Add("@EmailAddress", cccomparequest.EmailAddress);
			_sPara.Add("@FullName", cccomparequest.FullName);
			_sPara.Add("@MobileNo", cccomparequest.MobileNo);
			_sPara.Add("@DOB", cccomparequest.DOB);
			_sPara.Add("@ApplicantIdType", cccomparequest.IdType);
			_sPara.Add("@AnualIncome", cccomparequest.AnualIncome);
			_sPara.Add("@CardClass",cccomparequest.CreditCardClass);
			_sPara.Add("@UsageofCard", cccomparequest.UsageofCard);

            #region Comment @ 16042010
            //_sPara.Add("@LowIntrsRatePurchase",cccomparequest.LowInsRatePurchase == true ? 1 : 0);
            //_sPara.Add("@LowIntrsRateCash", cccomparequest.LowInsRateCash == true ? 1 : 0);
            //_sPara.Add("@LowAnualFee", cccomparequest.LowAnualFee == true ? 1 : 0);
            //_sPara.Add("@LowBalTransRate", cccomparequest.LowBalTransRate == true ? 1 : 0);
            //_sPara.Add("@IntrsFreePeriod", cccomparequest.InsFreePeriod == true ? 1 : 0);
            //_sPara.Add("@RewardsProgram", cccomparequest.RewardsProgram == true ? 1 : 0);
            //_sPara.Add("@TravelInsurance", cccomparequest.TravelInsurance == true ? 1 : 0);
            #endregion
            _sPara.Add("@ViewedDetailId", cccomparequest.ViewedDetailId);

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CreditCardCompareRequest GetAReqDetails(Int64 CCRQId)
        {
            CreditCardCompareRequest _ccappreq = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCCCApplicantRequestSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CCCAppReqId", CCRQId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _ccappreq = new CreditCardCompareRequest();
                    _ccappreq = FillDataRecord(_dt, 0);
                }
            }
            return _ccappreq;
        }

        private CreditCardCompareRequest FillDataRecord(DataTable myDataTable, int RowId)
        {
            CreditCardCompareRequest myReqDetails = new CreditCardCompareRequest();
            myReqDetails.CCCAppReqId = Convert.ToInt64(myDataTable.Rows[RowId]["CCCAppReqId"].ToString());
            myReqDetails.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myReqDetails.CreditCardClass = Convert.ToInt32(myDataTable.Rows[RowId]["CardClass"].ToString());
            myReqDetails.UsageofCard = Convert.ToInt32(myDataTable.Rows[RowId]["UsageofCard"].ToString());

            #region Comment @ 16042010
            //myReqDetails.LowInsRatePurchase = Convert.ToBoolean(myDataTable.Rows[RowId]["LowIntrsRatePurchase"].ToString());
            //myReqDetails.LowInsRateCash = Convert.ToBoolean(myDataTable.Rows[RowId]["LowIntrsRateCash"].ToString());
            //myReqDetails.LowAnualFee = Convert.ToBoolean(myDataTable.Rows[RowId]["LowAnualFee"].ToString());
            //myReqDetails.LowBalTransRate = Convert.ToBoolean(myDataTable.Rows[RowId]["LowBalTransRate"].ToString());
            //myReqDetails.InsFreePeriod = Convert.ToBoolean(myDataTable.Rows[RowId]["IntrsFreePeriod"].ToString());
            //myReqDetails.RewardsProgram = Convert.ToBoolean(myDataTable.Rows[RowId]["RewardsProgram"].ToString());
            //myReqDetails.TravelInsurance = Convert.ToBoolean(myDataTable.Rows[RowId]["TravelInsurance"].ToString());
            #endregion

            myReqDetails.FullName = myDataTable.Rows[RowId]["FullName"].ToString();
            myReqDetails.EmailAddress = myDataTable.Rows[RowId]["EmailAddress"].ToString();
            myReqDetails.MobileNo = myDataTable.Rows[RowId]["MobileNo"].ToString();
            myReqDetails.DOB = Convert.ToDateTime(myDataTable.Rows[RowId]["DOB"].ToString());
            myReqDetails.IdType = myDataTable.Rows[RowId]["ApplicantIdType"].ToString();
            myReqDetails.AnualIncome = Convert.ToInt32(myDataTable.Rows[RowId]["AnualIncome"].ToString());

            myReqDetails.ViewedDetailId = Convert.ToInt64(myDataTable.Rows[RowId]["ViewedDetailId"].ToString());

            return myReqDetails;
        }

    }
}
